import time
from autoframe.common.base import Base, By
from selenium.webdriver.support.ui import Select


class RegisterPage(Base):
    def click_register(self):
        # 点击免费注册
        self.find_element((By.LINK_TEXT, '免费注册')).click()

    # 用户名
    def input_username(self, username):
        self.find_element((By.NAME, 'username')).send_keys(username)

    def input_email(self, email):
        # 输入邮箱
        self.find_element((By.ID, 'email')).send_keys(email)

    def input_password1(self, password1):
        # 输入密码
        self.find_element((By.ID, 'password1')).send_keys(password1)

    def input_password(self, password):
        # 确认密码
        self.find_element((By.ID, 'conform_password')).send_keys(password)

    def input_qq(self, qq):
        # 输入qq
        self.find_element((By.NAME, 'extend_field2')).send_keys(qq)

    def input_office_telephone(self, telephone):
        # 输入办公号码
        self.find_element((By.NAME, 'extend_field3')).send_keys(telephone)

    def input_home_phone(self, phone):
        # 输入家庭电话
        self.find_element((By.NAME, 'extend_field4')).send_keys(phone)

    def input_phone(self, phone):
        # 输入手机
        self.find_element((By.NAME, 'extend_field5')).send_keys(phone)

    def select_password_prompt_question(self, article = '1'):
        # 输入提示问题
        sel_question = self.find_element((By.NAME, 'sel_question'))
        sel_question.click()
        select = Select(sel_question)
        select.select_by_index(article)

    def input_password_question_answer(self, answer):
        # 输入密码提示问题答案
        self.find_element((By.NAME, 'passwd_answer')).send_keys(answer)

    # 点击立即注册
    def register_now(self):
        self.find_element((By.CLASS_NAME, 'us_Submit_reg')).click()


    def log_out(self):
        # 退出
        self.find_element((By.LINK_TEXT, '退出')).click()
